/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clases;

import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfPCell;

import java.io.FileOutputStream;

import com.itextpdf.text.Font;
import com.itextpdf.text.Rectangle;
import java.io.FileNotFoundException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Owner
 */
public class ReportePreinscripcion extends Reporte {
    ArrayList <Preinscrito> preinscritos;
    ArrayList <Institucion> instituciones;
    ArrayList <Turno> turnos;
    ArrayList <Parada> paradas;

    public ReportePreinscripcion() {
    }

    public ArrayList<Institucion> getInstituciones() {
        return instituciones;
    }

    public void setInstituciones(ArrayList<Institucion> instituciones) {
        this.instituciones = instituciones;
    }

    public ArrayList<Parada> getParadas() {
        return paradas;
    }

    public void setParadas(ArrayList<Parada> paradas) {
        this.paradas = paradas;
    }

    public ArrayList<Preinscrito> getPreinscritos() {
        return preinscritos;
    }

    public void setPreinscritos(ArrayList<Preinscrito> preinscritos) {
        this.preinscritos = preinscritos;
    }

    public ArrayList<Turno> getTurnos() {
        return turnos;
    }

    public void setTurnos(ArrayList<Turno> turnos) {
        this.turnos = turnos;
    }
    
    
    
    
     public void generar(String path) throws FileNotFoundException {
        FileOutputStream f = new FileOutputStream(path);
        Document document = new Document();

        try {
            PdfWriter writer = PdfWriter.getInstance(document, f);
            Rectangle rct = new Rectangle(36, 54, 559, 788);
            //Definimos un nombre y un tamaño para el PageBox los nombres posibles son: “crop”, “trim”, “art” and “bleed”.
            writer.setBoxSize("art", rct);
            HeaderFooter event = new HeaderFooter(this.getId(), this.getNumAutenticacion());
            writer.setPageEvent(event);
            document.open();
            //Encabezado
            Font fuente = new Font(Font.getFamily("ARIAL"), 16, Font.BOLD);
            Font fuente1 = new Font(Font.getFamily("ARIAL"), 14, Font.BOLD);
            DateFormat dates = new SimpleDateFormat("dd/MM/yyyy");
            Date date = new Date();
            String encabezado = "\nCaracas " + dates.format(date) + "\n"
                    + "Programa de Igualdad de Oportunidades \n"
                    + "Reporte de PIO Nro." + getId() + "\n";
            Paragraph pa = new Paragraph(encabezado, fuente);
            pa.setSpacingBefore(20);
            pa.setSpacingAfter(15);
            pa.setIndentationLeft(50);
            document.add(pa);
            // 
            /**String s = "Numero total de aspirantes seleccionados para presentar el test vocacional: " + this.getNumPreselectos();
            Paragraph p = new Paragraph(s);
            p.setSpacingBefore(20);
            p.setSpacingAfter(0);
            p.setIndentationLeft(50);
            document.add(p);

            // 

            s = "Numero total de aspirantes que han presentado el test: " + this.getAspirantesTestCompletos().size();
            p = new Paragraph(s);
            p.setSpacingBefore(10);
            p.setSpacingAfter(0);
            p.setIndentationLeft(50);
            document.add(p);

            s = "Aspirantes que completaron su test:";
            p = new Paragraph(s, fuente1);
            p.setSpacingBefore(20);
            p.setSpacingAfter(20);
            p.setIndentationLeft(50);
            document.add(p);*/
            String s;
            PdfPTable table = new PdfPTable(9);
//            table.setWidthPercentage(100);
            s = "ID";
            PdfPCell cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Cedula";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Apellidos";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Nombres";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Aula";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Fecha";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Parada";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "HoraExamen";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);
            s = "Institucion";
            cell1 = new PdfPCell(new Paragraph(s));
            cell1.setBorder(PdfPCell.NO_BORDER);
            table.addCell(cell1);

            for (int i = 0; i < preinscritos.size(); i++) {
                Preinscrito c = (Preinscrito) preinscritos.get(i);
                PdfPCell cell0 = new PdfPCell(new Paragraph(String.valueOf(c.getId())+"-"+String.valueOf(c.getInstitucionId())));
                cell1 = new PdfPCell(new Paragraph(c.getCedula()));
                PdfPCell cell2 = new PdfPCell(new Paragraph(c.getApellidos()));
                PdfPCell cell3 = new PdfPCell(new Paragraph(c.getNombres()));
                PdfPCell cell4 = new PdfPCell(new Paragraph(c.getAulaPrueba()));
                PdfPCell cell5 = new PdfPCell(new Paragraph(getFecha(c.getTurnoPrueba())));
                PdfPCell cell6 = new PdfPCell(new Paragraph(getParada(c.getInstitucionId())));
                PdfPCell cell7 = new PdfPCell(new Paragraph(getHora(c.getTurnoPrueba())));
                PdfPCell cell8 = new PdfPCell(new Paragraph(getInstitucion(c.getInstitucionId())));
                //System.out.println(c.getInstitucionId());
                table.addCell(cell0);
                table.addCell(cell1);
                table.addCell(cell2);
                table.addCell(cell3);
                table.addCell(cell4);
                table.addCell(cell5);
                table.addCell(cell6);
                table.addCell(cell7);
                table.addCell(cell8);
                
            }
            document.add(table);
            document.close();
            f.flush();
            f.close();
        } catch (Exception e) {
            //imprimimos los errores
            System.err.println(e);
            e.printStackTrace();
        }
    }
     
     public String getInstitucion(int i) {
        String cel5 = "";
        for (Institucion iiii : getInstituciones()) {
            if (i == iiii.getId()) {
                cel5 = iiii.getNombre();
                break;
            }
        }
        return cel5;
    }
     
     public String getFecha(int i) {
        String cel5 = "";
        for (Turno iiii : getTurnos()) {
            if (i == iiii.getId()) {
                cel5 = iiii.getDia();
                break;
            }
        }
        return cel5;
    }
     
     public String getHora(int i) {
        String cel5 = "";
        for (Turno iiii : getTurnos()) {
            if (i == iiii.getId()) {
                cel5 = iiii.getHora();
                break;
            }
        }
        return cel5;
    }
     
     public String getParada(int i) {
        int aux;
        String cel5 = "";
        for (Institucion iiii : getInstituciones()) {
            if (i == iiii.getId()) {
                aux = iiii.getIdParada();
                for (Parada p : getParadas()){
                    if(aux==p.getId()){
                        cel5= p.getNombre();
                        break;
                    }
                }
            }
        }
        return cel5;
    }
    
    
}
